<template>
  <div class="login">
    <div class="bg">
    </div>
    <Modal class="login-modal" v-model="loginModal" width="360" :closable="false" :mask-closable="false">
      <div>
        <h2 style="margin:10px;color:#abcdef;text-align:center">
          <img :src="require('@/assets/img/logo.png')" alt="" height="50"></h2>
        <Form ref="formValidate" :model="formValidate" :rules="ruleValidate">
          <Form-item prop="notesid">
            <Input v-model="formValidate.notesid" placeholder="请输入notesid"></Input>
          </Form-item>
          <Form-item prop="password">
            <Input v-model="formValidate.password" @keyup.native.enter="handleSubmit('formValidate')" type="password" placeholder="请输入密码"></Input>
          </Form-item>
          <Row>
            <Col span="12">
            <Checkbox-group v-model="formValidate.remember">
              <Checkbox label="记住我"></Checkbox>
            </Checkbox-group>
            </Col>
          </Row>

        </Form>
      </div>
      <div slot="footer">
        <Button type="primary" size="large" long :loading="modal_loading" @click="handleSubmit('formValidate')">登录
        </Button>
        <small style="text-align: center;display:block" class="subText"></small>
      </div>
    </Modal>
  </div>
</template>
<script>
  import Cookies from 'js-cookie'
  export default {

    name: 'login',
    data () {
      return {
        loginModal: true,
        modal_loading: false,
        formValidate: {
          notesid: '',
          password: ''
        },
        ruleValidate: {
          notesid: [
            {required: true, message: 'notesid不能为空', trigger: 'blur'}
          ],
          password: [
            {required: true, message: '密码错误', trigger: 'blur'}
          ]
        }
      }
    },
    methods: {
      handleSubmit (notesid) { // login
        console.log(this.formValidate.notesid)
        this.$refs[notesid].validate((valid) => {
          // console.log(notesid)
          if (valid) {
            this.$Message.success('登录成功!')
            Cookies.set('token', this.formValidate.password)
            this.$router.push({path: '/index', query: {notesid: this.formValidate.notesid}})
          } else {
            this.$Message.error('登录失败!')
          }
        })
        /*
        this.$api.login(formValidate).then((res) => {
          if (res.resultCode === '10001') {
            this.$router.push({path: '/index', params: {role: res.role}})
          }
        })
        */
      }
    }
  }
</script>
